package com.baseframe.auth.config;

import com.baseframe.auth.props.AuthProvider;
import com.baseframe.auth.props.BaseAuthProperties;

import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;

import java.util.List;

@Configuration
@EnableResourceServer //自动装配资源服务
@AllArgsConstructor
public class BaseResourcesSecurityConfigurer extends ResourceServerConfigurerAdapter {

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.headers().frameOptions().disable();
        http.formLogin()
                .and()
                .authorizeRequests()
                .antMatchers(
                        "/oauth/captcha",
                        "/oauth/logout",
                        "/oauth/clear-cache",
                        "/oauth/render/**",
                        "/oauth/callback/**",
                        "/oauth/revoke/**",
                        "/oauth/refresh/**",
                        "/token/**",
                        "/mobile/**"
                ).permitAll()
                .anyRequest().authenticated().and()
                .csrf().disable();
    }

    private String[] getSkipUrls(){

        List<String> defaultSkipUrl = AuthProvider.getDefaultSkipUrl();
        return  defaultSkipUrl.toArray(new String[0]);

    }
}
